home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / util / blank / bserver_v14.lha / BServer_v1.4 / Sources.lha / Sources / clients / Mandelbrot.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-23  |  4.4 KB  |  207 lines

  1. ;/*
  2. sc RESOPT IGNORE=73 DATA=NEAR NMINC UCHAR CONSTLIB STREQ STRMERGE NOSTKCHK NOSTDIO OPTIMIZE OPTSIZE mandelbrot.c
  3. slink from LIB:c.o mandelbrot.o to //Clients/Mandelbrot LIB LIB:scm.lib LIB:sc.lib LIB:amiga.lib /lib/client.lib SC SD STRIPDEBUG NOICONS
  4. ; To compile for math coprocessor:
  5. sc DEFINE=MATH881 RESOPT IGNORE=73 DATA=NEAR NMINC UCHAR CONSTLIB STREQ STRMERGE NOSTKCHK NOSTDIO OPTIMIZE OPTSIZE  MATH=881 mandelbrot.c
  6. slink from LIB:c.o mandelbrot.o to //Clients/Mandel881 LIB LIB:scm881.lib LIB:sc.lib LIB:amiga.lib /lib/client.lib SC SD STRIPDEBUG NOICONS
  7. delete mandelbrot.o
  8. quit
  9.  
  10.  Mandelbrot 1.3  (Client for BServer)
  11.  
  12.  Copyright © 1994-1995 Luca Viola & Stefano Reksten of 3AM - The Three Amigos!!!
  13.  All rights reserved.
  14.  
  15.  Reworked and compiled also for 68881 as Massimo Capanni asked.
  16. */
  17.  
  18. #include <exec/types.h>
  19. #include <intuition/intuition.h>
  20. #include <graphics/gfxbase.h>
  21.  
  22. #include <proto/exec.h>
  23. #include <proto/intuition.h>
  24. #include <proto/graphics.h>
  25. #include <stdlib.h>
  26. #include <math.h>
  27. #include <time.h>
  28.  
  29. #include "/include/client.h"
  30.  
  31. #ifndef MATH881
  32. char *ver = "$VER: Mandelbrot 1.2 "__AMIGADATE__;
  33. #else
  34. char *ver = "$VER: Mandel881 1.2 "__AMIGADATE__;
  35. #endif
  36.  
  37. struct IntuitionBase *IntuitionBase;
  38. struct GfxBase *GfxBase;
  39. struct Library *BitMapBase;
  40.  
  41. struct DisplayIDInformation *dinfo;
  42. UBYTE command;
  43. BOOL stillBlanking;
  44.  
  45. #define XOFF        0
  46. #define YOFF         0
  47.  
  48. #define    RISX        240
  49. #define    RISY        240
  50. #define    PLANES        4
  51. #define    MAXITER        32
  52. #define    COLORS        (1 << PLANES)
  53.  
  54. /* function prototypes */
  55.  
  56. void Mandel( void );
  57. void DrawMandel( void );
  58.  
  59. /*  Intuition global  structures */
  60.  
  61. struct IntuitionBase *IntuitionBase;
  62. struct GfxBase *GfxBase;
  63. struct Screen *thescreen;
  64. struct RastPort *rport;
  65. struct ViewPort vport;
  66. struct BitMap *bitmap;
  67. ULONG *table;
  68.  
  69. UBYTE colors[]=
  70. {
  71.     0,0,0, 1,1,15, 2,2,14, 3,3,13, 4,4,12, 5,5,11, 6,6,10, 7,7,9,
  72.     8,8,8, 9,9,7, 10,10,6, 11,11,5, 12,12,4, 13,13,3, 14,14,2, 15,15,1
  73. };
  74.  
  75.  
  76. void Mandel()
  77. {
  78. UBYTE n, *col, brightness = GETBRIGHTNESS(dinfo);
  79. ULONG displayID = DISPLAYID(dinfo);
  80. UWORD rwidth;
  81. struct Rectangle *rect = GETTXTOSCANRECT(dinfo);
  82.  
  83. rwidth = RECTANGLEWIDTH(rect);
  84.  
  85. if ( !CheckAA() )
  86.     {
  87.     if ( displayID & SUPERHIRES )
  88.         {
  89.         displayID &= ~SUPERHIRES;
  90.         displayID |= HIRES;
  91.         rwidth >>= 1;
  92.         }
  93.     }
  94.  
  95. if ( thescreen = (struct Screen *)OpenScreenTags( NULL,
  96.         SA_Left, (rwidth - RISX)>>1,
  97.         SA_DisplayID, displayID,
  98.         SA_Width, RISX,
  99.         SA_Height, RISY,
  100.         SA_Depth, PLANES,
  101.         SA_Quiet, TRUE,
  102.         SA_Overscan, OSCAN_TEXT,
  103.         TAG_DONE ) )
  104.     {
  105.     col = colors;
  106.     for ( n = 0; n < 3<<PLANES; n++ )
  107.         {
  108.         *col = *col * brightness/100;
  109.         col++;
  110.         }
  111.  
  112.     rport=&(thescreen->RastPort);
  113.     vport=thescreen->ViewPort;
  114.     col= colors;
  115.     for ( n = 0; n < 1<<PLANES; n++ )
  116.         SetRGB4( &vport, n, *col++, *col++, *col++ );
  117.     DrawMandel();
  118.     CloseScreen( thescreen );
  119.     }
  120. else
  121.     SendClientMsg( ACTION_FAILED );
  122. }
  123.  
  124.  
  125. void DrawMandel()
  126. {
  127.     double quadsize;
  128.     double temp,xr,yr,d,vx,vy,x1real,y1imm,x2real,y2imm,gapx,gapy;
  129.     UWORD loop,x,y,risx,risy;
  130.  
  131.     SpritesOff();
  132.  
  133.     srand48( (unsigned int)time( NULL ) );    
  134.  
  135.     stillBlanking = TRUE;
  136.  
  137.     risx=RISX;
  138.     risy=RISY;
  139.  
  140.     while( stillBlanking )
  141.         {
  142.         quadsize = 3.4 * drand48();
  143.         x1real = -2.2 * drand48();
  144.         x2real = x1real + quadsize;
  145.         y1imm = -1.7 * drand48();
  146.         y2imm = y1imm + quadsize;
  147.  
  148.         gapx = ( x2real - x1real ) / risx;
  149.         gapy = ( y1imm - y2imm ) / risy;
  150.         vy = y2imm;
  151.  
  152.         for ( y = 0; y < RISY; y++ )
  153.             {
  154.             vy = vy + gapy;
  155.             vx = x1real;
  156.             for( x = 0; x < RISX && stillBlanking; x++ )
  157.                 {
  158.                 vx = vx + gapx;
  159.                 xr = 0; yr = 0;
  160.                 loop = 0;
  161.  
  162.                 do
  163.                     {
  164.                     loop++;
  165.                     temp = ( (xr*xr) - (yr*yr) ) + vx;
  166.                     yr = ( 2.0F * xr * yr ) + vy;
  167.                     xr = temp;
  168.                     d = xr * xr + yr * yr;
  169.                     if ( d > 4.0F )
  170.                         {
  171.                         SetAPen( &(thescreen->RastPort), loop%COLORS+1 );
  172.                         WritePixel( &(thescreen->RastPort), x, y );
  173.                           loop=MAXITER;
  174.                         }
  175.                     stillBlanking = STILL_BLANKING;
  176.                     }
  177.                 while(loop!=MAXITER && stillBlanking );
  178.  
  179.                 if ( stillBlanking && ( d < 4.0F ) )
  180.                     {
  181.                     SetAPen( &(thescreen->RastPort), 0 );
  182.                     WritePixel( &(thescreen->RastPort), x, y );
  183.                     }
  184.                 }
  185.             }
  186.         }
  187.     SpritesOn();
  188. }           
  189.  
  190.  
  191. void __main( char *line )
  192. {
  193. if ( IntuitionBase = (struct IntuitionBase *)OpenLibrary( "intuition.library", 37L ) )
  194.     {
  195.     if ( GfxBase = (struct GfxBase *)OpenLibrary( "graphics.library", 37L ) )
  196.         {
  197.         if ( dinfo = OpenCommunication() )
  198.             {
  199.             Mandel();
  200.             CloseCommunication( dinfo );
  201.             }
  202.         CloseLibrary( (struct Library *)GfxBase );
  203.         }
  204.     CloseLibrary( (struct Library *)IntuitionBase );
  205.     }
  206. }
  207.